package com.kunya.common.util;

import com.kunya.common.common.RedisPool;
import redis.clients.jedis.Jedis;

public class RedisPoolUtil {
	// redis set key value
		public static String set(String key, String value) {
			Jedis jedis = null;
			String result = null;
			try {
				jedis = RedisPool.getJedis();
				result = jedis.set(key, value);
			} catch (Exception e) {
				e.printStackTrace();
				return result;
			}
			RedisPool.returnResource(jedis);
			return result;

		}

		// redis setex
		public static String setex(String key, String value, int exTime) {
			Jedis jedis = null;
			String result = null;
			try {
				jedis = RedisPool.getJedis();
				result = jedis.setex(key, exTime, value);
			} catch (Exception e) {
				e.printStackTrace();
				return result;
			}
			RedisPool.returnResource(jedis);
			return result;

		}

		// redis expire
		public static Long expire(String key, int exTime) {
			Jedis jedis = null;
			Long result = null;
			try {
				jedis = RedisPool.getJedis();
				result = jedis.expire(key, exTime);
			} catch (Exception e) {
				e.printStackTrace();
				return result;
			}
			RedisPool.returnResource(jedis);
			return result;

		}

		// redis get value
		public static String get(String key) {
			Jedis jedis = null;
			String result = null;
			try {
				jedis = RedisPool.getJedis();
				result = jedis.get(key);
			} catch (Exception e) {
				e.printStackTrace();
				return result;
			}
			RedisPool.returnResource(jedis);
			return result;

		}
		
		
		// redis del
		public static Long del(String key) {
			Jedis jedis = null;
			Long result = null;
			try {
				jedis = RedisPool.getJedis();
				result = jedis.del(key);
			} catch (Exception e) {
				e.printStackTrace();
				return result;
			}
			RedisPool.returnResource(jedis);
			return result;

		}
		
		public static void main(String[] args) {
//			Jedis jedis=RedisPool.getJedis();
//			RedisShardedPoolUtil.set("1", "1r");
//			String value =RedisShardedPoolUtil.get("1");
//			RedisShardedPoolUtil.setex("2", "2r", 60*10);
//			RedisShardedPoolUtil.expire("1", 60*20);
//			RedisShardedPoolUtil.del("1");
		}
}
